<#assign module="zhuanche"/>
<@override name="header">
</@override>
<@override name="body">
<link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
<div class="row">
    <div class="col-xs-12">
        <button class="pull-right btn btn-primary create">添加保险信息</button>
    </div>
</div>
<div class="row margin-top">
    <div class="col-xs-12">
        <div class="panel panel-primary">
            <div class="table-responsive">
                <table class="table table-hover table-striped">
                    <thead>
                    <tr style="font-size:14px;">
                        <th>保险公司</th>
                        <th>保险号</th>
                        <th>保险类型</th>
                        <th>保险金额</th>
                        <th>保险生效时间</th>
                        <th>保险到期时间</th>
                        <th>车辆车牌号</th>
                        <th>操作</th>

                    </tr>
                    </thead>
                    <tbody id="settleAccountsCycleContent">
                        <#if (page.content)?? >
                            <#list page.content as data>
                            <tr>
                                <td>${data.insuranceCompany?if_exists}</td>
                                <td>${data.insuranceCode?if_exists}</td>
                                <td>${data.insuranceType?if_exists}</td>
                                <td>${data.insuranceAmount?if_exists}</td>
                                <td><#if data.insuranceValidDate??>${data.insuranceValidDate?string("yyyy-MM-dd")}</#if></td>
                                <td><#if data.insuranceEndDate??>${data.insuranceEndDate?string("yyyy-MM-dd")}</#if></td>
                                <td>${data.vehicleLicense?if_exists}</td>
                                <td>
                                    <a href="javascript:;" data-value="${data.id?if_exists}" class="btn-link red deletethis">删除</a>
                                </td>
                            </tr>
                            </#list>
                        </#if>
                    </tbody>
                </table>
                <#if page.totalElements??>
                    <ul class="pagination pull-right pagination-sm">
                        <li><a>共 ${page.totalElements} 条数据</a></li>
                        <!--
                         <@pg.pager items=page.totalElements?number maxPageItems=20 export="currentPageNumber=pageNumber" url="${ctx}/driverlevel/list">
                            <@pg.index>
                                <@pg.first>
                                    <li><a href="${pageUrl}">&laquo;</a></li>
                                </@pg.first>
                                <@pg.prev>
                                    <li><a href="${pageUrl}">&lsaquo;</a></li>
                                </@pg.prev>
                                <@pg.pages>
                                    <#if  currentPageNumber == pageNumber >
                                        <li class="active"><a href="#">${pageNumber}</a></li>
                                    <#else>
                                        <li><a href="${pageUrl}">${pageNumber}</a></li>
                                    </#if>
                                </@pg.pages>
                                <@pg.next>
                                    <li><a href="${pageUrl}">&rsaquo;</a></li>
                                </@pg.next>
                                <@pg.last>
                                    <li><a href="${pageUrl}">&raquo;</a></li>
                                </@pg.last>
                            </@pg.index>
                        </@pg.pager>
                        -->
                       
                    </ul>
                </#if>
            </div>
        </div>
    </div>
</div>

<!--添加-->
<div class="form-horizontal">
    <div class="modal fade" id="dialog_create" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="false">&times;</button>
                    <h4 class="modal-title">添加</h4>
                </div>
                <div class="modal-body">
                    <form action="" id="create_from"  method="post">
                        <input type="hidden" name="carId" value="${carId?if_exists}"/>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em>*</em>保险生效日期：</label>
                            <div class="col-sm-8">
                                <input class="form-control" id="insValidTime2" name="insuranceValidDate" type="text"  readonly/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em>*</em>&ensp;保险到期日期：</label>
                            <div class="col-sm-8">
                                <input class="form-control" id="insuranceTime2" name="insuranceEndDate" type="text"  readonly/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em>*</em>保险公司：</label>
                            <div class="col-sm-8">
                                <input class="form-control" id="insurer2" name="insuranceCompany" type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em>*</em>保险号：</label>
                            <div class="col-sm-8">
                                <input class="form-control" id="insuranceNo2" name="insuranceCode" type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em>*</em>保险类型：</label>
                            <div class="col-sm-8">
                                <input class="form-control" id="insType2" name="insuranceType" type="text"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em>*</em>保险金额：</label>
                            <div class="col-sm-8">
                                <input class="form-control" id="insMoney2" name="insuranceAmount" type="number"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-5">
                            </div>
                            <div class="col-sm-3">
                                <input  type="button" class="btn btn-primary" id="save" value="确定">
                                <button type="button" class="btn btn-default" data-dismiss="modal" id="close_modal">关闭</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>




</@override>
<@override name="footer">
<!--<script src="${ctx}/assets/js/zhuanche/insurance.js">-->
<script type="text/javascript">
    var thisButton;
    $(function(){

        $("#insuranceTime2").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true ,startDate:new Date()});
        $("#insValidTime2").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true ,endDate:new Date()});



        $(".create").click(function(){
            $("#dialog_create").modal();
        });

        $("#save").click(function(){
        
        	 if(!$('#insValidTime2').val()){
                $.scojs_message("请选择保险生效日期", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if($("#insuranceTime2").val() == ""){
                $.scojs_message("请填写保险到期时间", $.scojs_message.TYPE_ERROR);
                return false;
            }

            if(!$('#insurer2').val()){
                $.scojs_message("请填写保险公司", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if($('#insurer2').val().length > 50){
                $.scojs_message("保险公司名称超长", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if(!$('#insuranceNo2').val()){
                $.scojs_message("请填写保险号", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if($('#insuranceNo2').val().length > 50){
                $.scojs_message("保险号超长", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if(!$('#insType2').val()){
                $.scojs_message("请填写保险类型", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if(!$('#insType2').val().length > 50){
                $.scojs_message("保险类型超长", $.scojs_message.TYPE_ERROR);
                return false;
            }
            if(!$('#insMoney2').val()){
                $.scojs_message("请填写保险金额", $.scojs_message.TYPE_ERROR);
                return false;
            } else if (isNaN($('#insMoney2').val())){
                $.scojs_message("保险金额请填写数字", $.scojs_message.TYPE_ERROR);
                return false;
            }else if ($('#insMoney2').val()<=0 || $('#insMoney2').val()>10000000){
                $.scojs_message("保险金额有误，填写范围1~1000万", $.scojs_message.TYPE_ERROR);
                return false;
            }
           

            $.post(ctx+'/zhuanche/createInsurance',$('#create_from').serialize(),function(data){
                if(data.success){
                    $.scojs_message("成功", $.scojs_message.TYPE_OK);
                    $("#dialog_create").modal("hide");
                    $("#create_from")[0].reset();
                    setTimeout(function(){
                        window.location.reload(true);
                    }, 800);
                }else{
                    $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
                }

            })

        });

    });



    function deleteSettleAccountsCycle() {
        $.post('${ctx}/zhuanche/deletetInsurance',{'id':thisButton.attr("data-value")},function(data){
            if(data.success){
                thisButton.parent().parent().remove();
                $.scojs_message('删除成功', $.scojs_message.TYPE_OK);
            } else {
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            }
        },'json');
    }
    $(document).ready(function(){
        $(document).on("click",".deletethis",function(){
            thisButton = $(this);
            var confirm = $.scojs_confirm({
                content: "你真的要删除该结算保险信息吗？",
                action:deleteSettleAccountsCycle
            });
            confirm.show();
        });
    });

//上报车辆
    $(document).on("click",".reportAll",function(){
        thisButton = $(this);
        var confirm = $.scojs_confirm({
            content: "<P style='color: red' >你确定要上报所有车辆信息至监管平台吗？</P>",
            action:reportAllCar
        });
        confirm.show();
    });
    var reportAllTime;
    function reportAllCar(){
        $("#progressDiv").show();
        $("#upCar .modal-body .tempInfo").remove();
        $("#upCar .modal-body .spanInfo").remove();
        $("#upCar .modal-dialog").addClass("modal-sm");
        $("#loading").width(10);
        $.post("${ctx}/zhuanche/reportAll",{},function(data){
            if(data.code==0){
                $("#upCar").modal();
                reportAllTime = window.setInterval(function(){
                    var temp = $("#progressDiv").width();
                    var load = $("#loading").width();
                    if(load>=temp){
                        $("#loading").width(10);
                    }else{
                        $("#loading").width(load+10);
                    }
                },500);
                var tempInterval = window.setInterval(function(){
                    $.get(ctx+"/zhuanche/getCheckCarAllInfo",{},function(data){
                        if(data!=null){
                            if(data.reportAllCheck){
                                var str = "<p class='tempInfo'>";
                                var count=0;
                                var temp = data.reportAllData;
                                for(var key in temp){
                                    str +="["+key+"],"
                                    count++;
                                }
                                str+=" 数据验证不通过,请仔细检查!"
                                clearInterval(reportAllTime);
                                clearInterval(tempInterval);
                                $("#progressDiv").hide();
                                str+="</p>"
                                if(count==0){
                                    $("#upCar .modal-body").html("<span class='spanInfo'数据校验通过.是否继续上传<button type='button' id='upCarAllInfoButton' class='btn btn-info btn-sm' style='padding:2px 10px;''>继续</button></span>");
                                }else{
                                    $("#upCar .modal-dialog").removeClass("modal-sm");
                                    $("#upCar .modal-body").append(str)
                                }
                                ;
                            }

                        }
                    })

                },1000);

            }

        })

    }
    var upcarall;
    $(document).on("click","#upCarAllInfoButton",function(){
        $.post("${ctx}/zhuanche/#upCarAll",{},function(data){
            if(data.code==0){
                upcarall = window.setInterval(function(){
                    $.get("${ctx}/zhuanche/getupCarAllInfo",{},function(data){
                        if(data.success){
                            $.scojs_message( "成功:"+ata.upCarAllInfo.successNum+"  失败:"+data.upCarAllInfo.failNum, $.scojs_message.TYPE_OK);
                        }else{
                            $.scojs_message( "失败", $.scojs_message.TYPE_ERROR);
                        }
                    })
                },1000);
            }
        });


    })



</script>
</@override>
<@extends name="../layout.ftl"/>
